﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Video.Application.Contract.Base;
using Video.Application.Contract.UserInfos;
using Video.Application.Contract.UserInfos.Dtos;
using Video.Application.UserInfos;

namespace Video.HttpApi.Host.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserInfoController : ControllerBase
    {
        private readonly IUserInfoService _userInfoService;

        public UserInfoController(IUserInfoService userInfoService)
        {
            _userInfoService = userInfoService;
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<UserInfoRoleDto> GetAsync()
        {
            return await _userInfoService.GetAsync();
        }

        /// <summary>
        /// 编辑用户信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task UpdateAsync(UpdateUserInfoInput input)
        {
            await _userInfoService.UpdateAsync(input);
        }

        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<PageResultDto<UserInfoDto>> GetListAsync([FromQuery] GetListInput input)
        {
            return await _userInfoService.GetListAsync(input);
        }

        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Authorize(Roles ="admin")]
        [HttpDelete("list")]
        public async Task DeleteAsync(IEnumerable<Guid> id)
        {
            await _userInfoService.DeleteAsync(id);
        }

        /// <summary>
        /// 禁用用户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut("forbidden")]
        public async Task ForbiddenAsync(IEnumerable<Guid> id)
        {
            await _userInfoService.ForbiddenAsync(id);
        }
    }
}
